﻿/*
 * History:
 * ----------------
 * review by   : Yaser
 * review date : JUL-21-09
 * ----------------
 * by : Yaser
 * date : Feb 26th 11
 * changes:
 *   replace RolesCollection with List<Roles> to get the wcf service working
 * ----------------
 */
using System;
using System.Collections.Generic;
using ERP.Business.DataTypes.Users.Credentials;

namespace ERP.Business.DataTypes.Users
{
    /// <summary>
    /// User
    /// </summary>
    [Serializable]
    [System.Runtime.Serialization.KnownType(typeof(User))]
    public class User : BaseTypes.BaseType
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="User"/> class.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        public User(string username, string password)
        {
            Username = username;
            Password = password;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="User"/> class.
        /// </summary>
        public User()
        {
            Status = UserStatus.None;
            Roles = new List<Role>();
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the username.
        /// </summary>
        /// <value>The username.</value>
        [System.Runtime.Serialization.DataMember]
        public string Username
        {
            get;
            set;
        }


        /// <summary>
        /// Gets or sets the status.
        /// </summary>
        /// <value>The status.</value>
        [System.Runtime.Serialization.DataMember]
        public UserStatus Status
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the password.
        /// </summary>
        /// <value>The password.</value>
        [System.Runtime.Serialization.DataMember]
        public string Password
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the employee ID.
        /// </summary>
        /// <value>The employee ID.</value>
        [System.Runtime.Serialization.DataMember]
        public string EmployeeID
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the roles.
        /// </summary>
        /// <value>The roles.</value>
        [System.Runtime.Serialization.DataMember]
        public List<Role> Roles
        {
            get;
            set;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        /// </summary>
        /// <param name="x">The first object to compare.</param>
        /// <param name="y">The second object to compare.</param>
        /// <returns>
        /// A signed integer that indicates the relative values of <paramref name="x"/> and <paramref name="y"/>, as shown in the following table.Value Meaning Less than zero <paramref name="x"/> is less than <paramref name="y"/>. Zero <paramref name="x"/> equals <paramref name="y"/>. Greater than zero <paramref name="x"/> is greater than <paramref name="y"/>.
        /// </returns>
        /// <exception cref="T:System.ArgumentException">Neither <paramref name="x"/> nor <paramref name="y"/> implements the <see cref="T:System.IComparable"/> interface.-or- <paramref name="x"/> and <paramref name="y"/> are of different types and neither one can handle comparisons with the other. </exception>
        public override int Compare(object x, object y)
        {
            if (ERP.Framework.Components.Utilities.ComparingHelper.ComapringManager.CompareTypes(x, y))
                return ((User)x).Username.CompareTo(((User)y).Username);
            return -1;
        }

        #endregion
    }
}
